import numpy as np
from scipy import signal
from skimage import data
from matplotlib import pyplot as plt
# 定义二维灰度图像的空间滤波函数
def correl2d(img, window):
    s = signal.correlate2d(img, window, mode ='same',boundary ='fill')
    return s
# img为原始图像
img = data.camera()
# 3*3盒状滤波模板
window = np.ones((3, 3)) / (3 ** 2)
img_blur = correl2d(img, window)
img_edge = img - img_blur
img_enhance = img + img_edge
# 显示图像
plt.rcParams['font.sans-serif'] = ['SimHei'] 
plt.rcParams['axes.unicode_minus'] = False
plt.subplot(2, 2, 1)
plt.axis('off')
plt.imshow(img, cmap = 'gray')
plt.title('原图像')
plt.subplot(2, 2, 2)
plt.axis('off')
plt.imshow(img_blur, cmap = 'gray')
plt.title('模糊图像')
plt.subplot(2, 2, 3)
plt.axis('off')
plt.imshow(img_edge, cmap = 'gray')
plt.title('差值图像')
plt.subplot(2, 2, 4)
plt.axis('off')
plt.imshow(img_enhance, cmap = 'gray')
plt.title('锐化增强')
plt.savefig('反锐化掩蔽.tif')
